package com.astar.mapper;

import com.astar.entity.*;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Select;
import org.springframework.stereotype.Repository;

import java.sql.Wrapper;
import java.util.List;

/**
 * <p>
 * 用户信息表 Mapper 接口
 * </p>
 *
 * @author jobob
 * @since 2020-01-17
 */
@Repository
public interface UserMapper extends BaseMapper<User> {
    @Select("select count(*) from sys_user where login_name=#{loginName}")
    int selectUserForLoginName(String loginName);

    @Select("select * from sys_user where login_name=#{loginName} and password=#{password}")
    User selectUser(String loginName,String password);

    @Select("select * from sys_user where login_name=#{loginName}")
    User selectUserForUserName(String loginName);

    @Select("select m.perms from sys_user u INNER JOIN sys_user_role ur on u.user_id = ur.user_id INNER JOIN sys_role r on r.role_id = ur.role_id INNER JOIN sys_role_menu rm on r.role_id = rm.role_id INNER JOIN sys_menu m on m.menu_id=rm.menu_id where u.login_name=#{loginName}")
    List<Menu> selectMenuFromLoginName(String loginName);

    @Select("select u.user_id,u.login_name,r.role_id,r.role_name,m.menu_id,m.parent_id,m.menu_name,m.perms,m.url,m.icon from sys_user u INNER JOIN sys_user_role ur on u.user_id = ur.user_id  INNER JOIN sys_role r on r.role_id = ur.role_id  INNER JOIN sys_role_menu rm on r.role_id = rm.role_id  INNER JOIN sys_menu m on m.menu_id=rm.menu_id  where u.login_name=#{loginName}")
    List<CustomUser> selectUserPower(String loginName);

    //显示界面
    List<CustomUser> selectAll(Integer id);

    @Select("select * from sys_role where role_id = #{id,jdbcType=INTEGER}")
    Role selectAllForId(Integer id);

    //部门树
    List<Dept> selectDepTree();

    //查询所有
    @Select("select user_id id,user_name name from sys_user")
    List<User> select();

    List<CusUser> queryUserByDeptId(CusUser cusUser);
    @Select("select u.*,d.dept_name as deptName  from sys_dept d,sys_user u where u.dept_id=d.dept_id and u.user_id = #{id}")
    CusUser selectForId(Integer id);



}
